import objgraph
import schedule
import guppy
# from guppy import hpy
#
# hp=hpy()
#
# heap = hp.heap()  # 返回heap内存详情
#
# print('=========')
#
# # hp.heap().byid[0].sp
# #
# print('=========')
#
# references = heap[0].byvia  # byvia返回该对象的被哪些引用， heap[0]是内存消耗最大的对象
# print('references')


from guppy import hpy
from pkgcore.config import load_config
# c = load_config()
hp = hpy()

# Do everything that allocates some memory but is not the problem you are tracking down now.
# hp.setrelheap()

# Now do your memory-intensive thing:
# l = list(x for x in c.repo["portdir"] if x.data)

# Keep an eye on system memory consumption. You want to use up a lot but not all of your system ram for nicer statistics. The python process was eating about 109M res in top when the above stuff finished, which is pretty good (for my 512mb ram box).
h = hp.heap()

# his object is basically a snapshot of what's reachable in ram (minus the stuff excluded through setrelheap earlier) which you can do various fun tricks with. Its str() is a summary:
h

# You probably guessed what you can use "index" for:
h[0]

# We can also partition the sets by a different equivalence relation. Let's do a silly example first:
h.bytype

# As you can see this is the same thing as the default view, but with all the dicts lumped together. A more useful one is:
h.byrcs

